<!DOCTYPE html>
<html>
<head>
  <title><%= title %></title>
  <link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
  <h1>Welcome to <%= title %></h1>
  <input type="button" value="用户登录" onclick="user_login()">
  <br />
  <input type="button" value="验证Token" onclick="verify_token()">
  <br />
  <input type="button" value="用户登录2" onclick="user_login2()">
  <br />
  <input type="button" value="验证Token2" onclick="verify_token2()">
</body>
</html>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
  function user_login() {
    console.log('user login');
    $.ajax({
      type: "post",
      url: "/users/jwt/login",
      success: function (res) {
        if (res.success) {
          localStorage.setItem('tokenid', res.tokenid);
          // window.location.href = './test.html'
        } else {
          alert(res.err)
        }
      },
      error: function (err) {
        console.log(err);
      }
    });
  }
  function verify_token() {
    console.log('verify token');
    $.ajax({
      type: "post",
      url: "/users/jwt/verifytoken",
      headers: {
        Authorization: localStorage.getItem('tokenid')
      },
      success: function (data) {
        console.log(data);
      },
      error: function (err) {
        console.log(err);
      }
    });
  }

  function user_login2() {
    console.log('user login');
    $.ajax({
      type: "post",
      url: "/users/jwt/login2",
      success: function (res) {
        if (res.success) {
          localStorage.setItem('tokenid2', res.tokenid);
          // window.location.href = './test.html'
        } else {
          alert(res.err)
        }
      },
      error: function (err) {
        console.log(err);
      }
    });
  }
  function verify_token2() {
    console.log('verify token');
    $.ajax({
      type: "post",
      url: "/users/jwt/verifytoken2",
      headers: {
        Authorization: localStorage.getItem('tokenid2')
      },
      success: function (data) {
        console.log(data);
      },
      error: function (err) {
        console.log(err);
      }
    });
  }
</script>